package br.com.felix.easyclearcase.tasks;

import java.util.concurrent.Semaphore;


/**
 * Base class for tasks that need to be run in sequence.
 * Currently, it has no uses.
 * */
public abstract class SequencedTask extends Task {
	
	private static Semaphore semaphore = new Semaphore(1);
	
	@Override
	public void cancel() {
	}
	
	
	


	@Override
	public void run() {
		try {
			semaphore.acquire();
		}
		catch (InterruptedException e) {
			changeStatus(TaskStatus.COMPLETE_FAIL);
			return;
		}
		changeStatus(TaskStatus.IN_PROGRESS);
		doRun();
		if(singleThreaded()){
			changeStatus(TaskStatus.COMPLETE_SUCCESS);
		}
		semaphore.release();
	}


	public abstract void doRun();


	@Override
	public TaskPriority getTaskPriority() {
		return TaskPriority.NORMAL;
	}
	
	
	public abstract boolean singleThreaded();
}
